using System;

namespace Atomic.Structures
{
	public static class StructureHelper
	{
		public static Structure CreateFaceCenteredCubicStructure(double a, Atom atom)
		{
			return Structure.CreateFaceCenteredCubicStructure(a)
				.Add(atom, 0.0, 0.0, 0.0);
		}

		public static Structure CreateFaceCenteredCubicStructureOctahedral(double a, Atom atom, Atom interstitialAtom)
		{
			return CreateFaceCenteredCubicStructure(a, atom)
				.Add(interstitialAtom, 0.5, 0.5, 0.5);
		}

		public static Structure CreateConventionalFaceCenteredCubicStructure(double a, Atom atom)
		{
			return CreateConventionalFaceCenteredCubicStructure(a, atom, atom, atom, atom);
		}

		public static Structure CreateConventionalFaceCenteredCubicStructure(double a, Atom atom1, Atom atom2, Atom atom3, Atom atom4)
		{
			return Structure.CreateSimpleCubicStructure(a)
				.Add(atom1, 0.0, 0.0, 0.0)
				.Add(atom2, 0.0, 0.5, 0.5)
				.Add(atom3, 0.5, 0.0, 0.5)
				.Add(atom4, 0.5, 0.5, 0.0);
		}

		public static Structure CreateConventionalFaceCenteredCubicStructureOctahedral(double a, Atom atom, Atom interstitialAtom)
		{
			return CreateConventionalFaceCenteredCubicStructureOctahedral(a, atom, atom, atom, atom, interstitialAtom, interstitialAtom, interstitialAtom, interstitialAtom);
		}

		public static Structure CreateConventionalFaceCenteredCubicStructureOctahedral(double a, Atom atom1, Atom atom2, Atom atom3, Atom atom4, Atom interstitialAtom1, Atom interstitialAtom2, Atom interstitialAtom3, Atom interstitialAtom4)
		{
			// http://www.materials.ac.uk/elearning/matter/IntroductionToPointDefects/Interstitials/interstitial-fcc2.html
			return CreateConventionalFaceCenteredCubicStructure(a, atom1, atom2, atom3, atom3)
				.Add(interstitialAtom1, 0.5, 0.0, 0.0)
				.Add(interstitialAtom2, 0.0, 0.5, 0.0)
				.Add(interstitialAtom3, 0.0, 0.0, 0.5)
				.Add(interstitialAtom4, 0.5, 0.5, 0.5);
		}

		public static Structure CreateHexagonalStructure(double a, Atom atom)
		{
			return CreateHexagonalStructure(a, atom, atom);
		}

		public static Structure CreateHexagonalStructure(double a, Atom atom1, Atom atom2)
		{
			// Ideal ratio 3c^2=8a^2.
			return CreateHexagonalStructure(a, a * 1.6329931618554521, atom1, atom2);
		}

		public static Structure CreateHexagonalStructure(double a, double c, Atom atom)
		{
			return CreateHexagonalStructure(a, c, atom, atom);
		}

		public static Structure CreateHexagonalStructure(double a, double c, Atom atom1, Atom atom2)
		{
			return Structure.CreateHexagonalStructure(a, c)
				.Add(atom1, 0.0, 0.0, 0.0)
				.Add(atom2, 1.0 / 3.0, 1.0 / 3.0, 0.5);
		}

		public static Structure CreateHexagonalStructureOctahedral(double a, Atom atom, Atom interstitialAtom)
		{
			return CreateHexagonalStructureOctahedral(a, atom, atom, interstitialAtom, interstitialAtom);
		}

		public static Structure CreateHexagonalStructureOctahedral(double a, Atom atom1, Atom atom2, Atom interstitialAtom1, Atom interstitialAtom2)
		{
			// Ideal ratio 3c^2=8a^2.
			return CreateHexagonalStructureOctahedral(a, a * 1.6329931618554521, atom1, atom2, interstitialAtom1, interstitialAtom2);
		}

		public static Structure CreateHexagonalStructureOctahedral(double a, double c, Atom atom, Atom interstitialAtom)
		{
			return CreateHexagonalStructureOctahedral(a, c, atom, atom, interstitialAtom, interstitialAtom);
		}

		public static Structure CreateHexagonalStructureOctahedral(double a, double c, Atom atom1, Atom atom2, Atom interstitialAtom1, Atom interstitialAtom2)
		{
			return CreateHexagonalStructure(a, c, atom1, atom2)
				.Add(interstitialAtom1, 2.0 / 3.0, 2.0 / 3.0, 0.25)
				.Add(interstitialAtom1, 2.0 / 3.0, 2.0 / 3.0, 0.75);
		}
	}
}
